home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / isam / keysrch / keysrch.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-07  |  1.9 KB  |  103 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <assert.h>
  6.  
  7. #include "fileinfo.h"
  8. #include "keyword.h"
  9. #include "xref.h"
  10. #include "match.h"
  11.  
  12. dfFILEINFO fileinfo;
  13. dfKEYWORD  keyword;
  14. dfXREF     xref;
  15. dfMATCH    match;
  16.  
  17.  
  18. void zap_match_file(void)
  19.     {
  20.     match.rew();
  21.     while (match.next() != -1)
  22.         {
  23.         match.erase();
  24.         }
  25.     }
  26.  
  27. void process(char *key, int keyno)
  28.     {
  29.     int no_matches = 0;
  30.     strcpy(keyword.name, key);
  31.     if (keyword.find() == -1)
  32.         if (keyword.retrieve() == -1)
  33.             return;
  34.     while (strncmp(keyword.name, key, strlen(key)) == 0)
  35.         {
  36.         xref.keyno = keyword.keyno;
  37.         xref.fileno = 0;
  38.         if (xref.find() == -1)
  39.             assert(xref.retrieve() != -1);
  40.         while (xref.keyno == keyword.keyno)
  41.             {
  42.             match.fileno = xref.fileno;
  43.             match.keyno = keyno;
  44.             if (match.find() == -1)
  45.                 {
  46.                 match.insert();
  47.                 no_matches++;
  48.                 }
  49.             if (xref.next() == IM_ERROR)
  50.                 break;
  51.             }
  52.         if (keyword.next() == IM_ERROR)
  53.             break;
  54.         }
  55.     printf("%d Matches\n", no_matches);
  56.     }
  57.  
  58. void report(int count)
  59.     {
  60.     int cur_fileno = -1, x = 0, total_matches = 0;
  61.     match.rew();
  62.     for (;;)
  63.         {
  64.         int retval = match.next();
  65.         if (match.fileno != cur_fileno || retval == -1)
  66.             {
  67.             if (x == count)
  68.                 {
  69.                 fileinfo.fileno = cur_fileno;
  70.                 assert(fileinfo.find() != -1);
  71.                 printf("Matching File: %s\n", fileinfo.path);
  72.                 total_matches++;
  73.                 }
  74.             x = 1;
  75.             cur_fileno = match.fileno;
  76.             }
  77.         else
  78.             x++;
  79.         if (retval == -1)
  80.             break;
  81.         }
  82.     printf("Total Matches: %d\n", total_matches);
  83.     }
  84.  
  85. int main(int argc, char *argv[])
  86.     {
  87.     if (argc < 2)
  88.         return 0;
  89.     fileinfo.set_idx("File No");
  90.     zap_match_file();
  91.     for (int x = 1; x < argc; x++)
  92.         {
  93.         if (strlen(argv[x]) > 10)
  94.             argv[x][10] = 0;
  95.         strupr(argv[x]);
  96.         printf("Checking Key: %s - ", argv[x]);
  97.         process(argv[x], x - 1);
  98.         }
  99.     report(argc - 1);
  100.     return 0;
  101.     }
  102.  
  103.